/**
 * @class NG.response.PutInfoEx
 * @extends Ext.util.Observable
 * 
 */
NG.response.PutInfoEx = Ext.extend(NG.response.Response, {
	
	/**
	 * Object that handles the response of the put info command.
	 * @cfg transactionalResult
	 */
	transactionalResult: {
		Inserted: "0",
		Deleted: "0",
		Updated: "0",
		Message: "",
		isSuccessful: function(){
			if (this["wfs:Status"] && (typeof this["wfs:Status"]["wfs:SUCCESS"] !== "undefined"))
				return true;
			return false;
		}
	},
	
	/**
	 * @private
	 * @param {Object} config
	 */
	constructor: function(config){
		NG.response.PutInfoEx.superclass.constructor.call(this, config);
	},
	
	/**
	 * 
	 * @return {Boolean} whether putinfo resulted successfully
	 */
	isSuccessful: function (){
		return this.transactionalResult.isSuccessful();
	},
	
	/**
	 * Message can be read if the request fails.
	 * @return {String} message that response has.
	 */
	getMessage: function (){
		return this.transactionalResult.Message;
	}, 

	/**
	 * 
	 * @return {Integer} inserted rows count
	 */
	getInsertedCount: function (){
		var result = parseInt(this.transactionalResult.Inserted);
		if (!Ext.isNumber(result))
			return 0;
		return result;
	},
	
	/**
	 * 
	 * @return {Integer} deleted rows count
	 */
	getDeletedCount: function (){
		var result = parseInt(this.transactionalResult.Deleted);
		if (!Ext.isNumber(result))
			return 0;
		return result;
	},
	
	/**
	 * 
	 * @return {Integer} updated rows count
	 */
	getUpdatedCount: function (){
		var result = parseInt(this.transactionalResult.Updated);
		if (!Ext.isNumber(result))
			return 0;
		return result;
	},
	
	getAffectedRecordCount: function (){
		var dmlType = this.getCommand().dmlType;
		if ("delete" === dmlType) return this.getDeletedCount();
		if ("update" === dmlType) return this.getUpdatedCount();
		if ("insert" === dmlType) return this.getInsertedCount();
	},
	
	/**
	 * @private
	 * @param {String} xmlData xml formated string
	 */
	init: function (xmlData) {
		NG.response.PutInfoEx.superclass.init.call(this, xmlData);
		this.parseXMLData(xmlData);
	},
	
	/**
	 * Parses the xmlData.
	 * @param {String} xmlData xml formatted string.
	 */
	parseXMLData: function (xmlData){
		this.featureMap = new Ext.util.HashMap();
		var xmlStr = fleegix.xml.parse(fleegix.xml.createDoc(xmlData), 'string').string;
		var xmlDoc = fleegix.xml.createDoc(xmlStr);
		var response = fleegix.xml.parse(xmlDoc)["wfs:TransactionResponse"];
		if (response["wfs:TransactionResult"])
			this.transactionalResult = Ext.apply(this.transactionalResult, response["wfs:TransactionResult"]);
		else
			this.transactionalResult = Ext.apply(this.transactionalResult, response);
		var message = fleegix.xml.parse(xmlDoc, "Message")["Message"];
		if (message)
			this.transactionalResult.Message = message;
	},
	
	/**
	 * This must be call super class's init function to detect any exception.
	 * @private
	 */
	init: function (xmlData) {
		NG.response.PutInfoEx.superclass.init.call(this, xmlData);
		this.parseXMLData(xmlData);
	}
	
});